package com.thoughtworks.studentManagement.controller;

import com.thoughtworks.studentManagement.model.Student;
import com.thoughtworks.studentManagement.service.StudentService;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
class StudentController {

    private final StudentService studentService;

    StudentController(StudentService studentService) {
        this.studentService = studentService;
    }

    /**
     * 功能1：获取全部学生信息
     */
    @GetMapping("/getAllStudents")
    @ResponseStatus(value = HttpStatus.OK)
    List<Student> getAllStudents() {
        return studentService.getAllStudents();
    }

    /**
     * 功能2：获取某个学生信息
     */
    @GetMapping("/getOneStudent/{studentNumber}")
    Student getOneStudent(@PathVariable String studentNumber) {
        return studentService.getOneStudent(studentNumber);
    }

    /**
     * 功能3：增加一名学生
     */
    @PostMapping("/createNewStudent")
    Student createNewStudent(@RequestBody Student newStudent) {
        return studentService.createNewStudent(newStudent);
    }

    /**
     * 功能4：修改某个学生信息
     */
    @PutMapping("/updateStudentInformation/{studentNumber}")
    Student updateStudentInformation(@RequestBody Student newStudent, @PathVariable String studentNumber) {
        return studentService.updateStudentInformation(newStudent, studentNumber);
    }

    /**
     * 功能5：删除某个学生
     */
    @DeleteMapping("/deleteOneStudent/{studentNumber}")
    void deleteOneStudent(@PathVariable String studentNumber) {
        studentService.deleteOneStudent(studentNumber);
    }

    /**
     * 附加：根据studentNumber修改某个学生姓名
     */
    @PatchMapping("/partialUpdateStudentName/{studentNumber}")
    Integer partialUpdateStudentName(@RequestParam String newStudentName, @PathVariable String studentNumber) {
        return studentService.partialUpdateStudentName(newStudentName, studentNumber);
    }

}
